#include <iostream>

class Obj {
private:
    int refCount;

public:
    Obj() {
        refCount = 1;
        std::cout << "Create Obj\n";
    };

    void sayHello() {
        std::cout << "Hello World!\n";
    }

    void retain() {
        refCount++;
    }

    void release() {
        refCount--;
        if (refCount == 0) {
            delete this;
        }
    }

    ~Obj() {
        std::cout << "Destroy Obj\n";
    };
};


int main() {
    auto obj = new Obj();
    obj->sayHello();
    obj->release();

    // obj->retain();
    // obj->release();
    return 0;
}
